package com.itboye.ihomebank.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * Created by itboye on 2017/2/10.
 */

public abstract class CommoAdapter<T> extends BaseAdapter{

    /**
     * 上下文
     */
    protected Context context;
    /**
     * 数据源
     */
    protected List<T> listDatas;
    /**
     * Item布局ID
     */
    protected int layoutId;


    public CommoAdapter(Context context, List<T> listDatas, int layoutId){
        this.context=context;
        this.listDatas=listDatas;
        this.layoutId=layoutId;

    }
    @Override
    public int getCount() {
        return listDatas==null?0:listDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHouder holder = ViewHouder.getViewHolder(context, convertView,
                parent, layoutId);
        fillData(holder, position);
        return holder.getMConvertView();
    }
    /**
     * 填充数据
     *
     * @param holder
     * @param position
     */
    protected abstract void fillData(ViewHouder holder, int position);
}
